import * as type from './mutations-type'
import service from "@/service/index_c";
import Vue from 'vue'
export const setAllMenu = ({
    commit
}, item) => {
    // comsole.log(item)
    commit(type.ALL_MENU, item);
};
export const setAllDepatement = ({
    commit
}) => {
    getAllDepateMent(res => {
        commit(type.ALL_DEPATEMENT, res);
    })

};
export const setMenuItem = ({
    commit
}, item) => {
    commit(type.MENU_ITEM, item);
};
export const setNavName = ({
    commit
}, item) => {
    commit(type.NAV_ITEM, item);
};


export const setRolesList = ({
    commit
}, item) => {
    getAllRolesList(res => {
        commit(type.ROLES_LIST, res)
    })
};


export const setAllAngentLists = ({
    commit
}, status) => {
    if (status === 'officel') {
        queryOfficialAgentList(res => {
            commit(type.ANGENT_LISTS, res)
        })
    } else {
        getAllAngentList(res => {
            commit(type.ANGENT_LISTS, res)
        })
    }

};


//获取全部的部门 
async function getAllDepateMent(cb) {
    let result = await service.haiheiServerDepateMentList();
    if (result.success) {
        let list = result.result;
        cb(list)
    } else {
        this.$message({
            type: 'error',
            message: '获取失败'
        })
    }
}

//获取全部的角色
async function getAllRolesList(cb) {
    let result = await service.haibeiQueryAllRolesList();
    if (result.success) {
        let list = result.result;
        cb(list)

    } else {
        this.$message({
            type: 'error',
            message: '获取失败'
        })
    }
}
// 获取全部经纪商 原始的所有经纪商（无官方）
async function getAllAngentList(cb) {
    let result = await service.haiheiAllOldAngentList();
    if (result.success) {
        let list = result.result;
        cb(list)
    } else {
        this.$message({
            type: 'error',
            message: '获取失败'
        })
    }
}

//获取官方的经纪商列表 包含官方和其他经纪商
async function queryOfficialAgentList(cb) {
    let res = await service.haiheiQueryOfficialAgentList()
    if (res.success) {
        cb(res.result)
        // this.getAngents=res.result;
    }
}